package com.tanhua.dubbo.api;


import com.tanhua.domain.mongo.Voice;
import com.tanhua.dubbo.api.mongo.VoiceApi;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;

@DubboService
public class VoiceApiImpl implements VoiceApi {

    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public void save(Voice voice) {
        mongoTemplate.insert(voice);
    }

    @Override
    public List<Voice> getSound(Long userId, String gender) {

        Query query = new Query(Criteria.where("userId").nin(userId).and("gender").nin(gender));
        List<Voice> voices = mongoTemplate.find(query, Voice.class);

        return voices;
    }
}
